package bcxd.firstline.appmaster.machining;

import java.sql.Connection;
import java.util.Map;

import jt.classic.system.context.ISystemContext;
import jt.classic.system.user.IUser;

import org.limp.basework.MachiningException;
import org.limp.basework.SimpleBean;
import org.limp.basework.SimpleBeanMachining;
import org.limp.basework.Table;
import org.limp.basework.impl.CommonBean4HSQ;
import org.limp.mine.StringTool;

import bcxd.firstline.user.manager.AppUserManager;

public class EditUserLogidMachining implements SimpleBeanMachining {

	public SimpleBean machining(SimpleBean arg0, Table arg1,
			CommonBean4HSQ arg2, Connection arg3, int arg4)
			throws MachiningException {
		
		
		// TODO Auto-generated method stub
		if (arg4 == -4) {
			IUser sessionUser = ISystemContext.getSessionUser(arg2.getRequest());
			
			Map param = arg2.getResource();

			String logid = StringTool.checkString(param.get("logid"));
			String pwd = StringTool.checkString(param.get("_pwd"));
			String newLogid = StringTool.checkString(param.get("newLogid"));

			AppUserManager manager = new AppUserManager(arg3);

			if (manager.checkLogidPwd(logid, pwd)) {
				arg0.getResource().put("uid", sessionUser.id());
				arg0.getResource().put("logid", newLogid);
			} else {
				throw new MachiningException("密码校验失败");
			}
		}
		return null;
	}

}
